package com.zzh.lib.core.loader;


import android.content.Context;
import android.provider.MediaStore;
import android.text.TextUtils;

import com.zzh.lib.core.HLibrary;

import androidx.annotation.NonNull;
import androidx.loader.content.CursorLoader;

/**
 * Created by ZZH on 2023/2/1.
 *
 * @date: 2023/2/1 17:16
 * @email: zzh_hz@126.com
 * @author: zzh
 * @description: com.zzh.lib.core.loader 查询所有的文件
 */
public class HFileLoader extends CursorLoader {

    private static final String[] FILE_PROJECTION = {
            //Base File
            MediaStore.Files.FileColumns._ID,
            MediaStore.Files.FileColumns.TITLE,
            MediaStore.Files.FileColumns.DATA,
            MediaStore.Files.FileColumns.SIZE,
            MediaStore.Files.FileColumns.DATE_ADDED,
            //Normal File
            MediaStore.Files.FileColumns.MIME_TYPE
    };

    public HFileLoader(@NonNull Context context) {
        super(context);
        setProjection(FILE_PROJECTION);
        setUri(MediaStore.Files.getContentUri("external"));
        setSortOrder(MediaStore.Files.FileColumns.DATE_ADDED + " DESC");
        if (!TextUtils.isEmpty(HLibrary.getFileSelection())) {
            setSelection(HLibrary.getFileSelection());
        }
        if (HLibrary.getFileSelectionArgs() != null) {
            setSelectionArgs(HLibrary.getFileSelectionArgs());
        }
    }
}
